<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.fick.hibernate.model.Admin"%>
<%@ page import="com.fick.hibernate.dao.*" %>
<%@ page import="java.util.List" %>
<%@page import="com.fick.hibernate.dao.RoleDAO"%>
<%@page import="com.fick.hibernate.model.Role"%>

      <%
      String adminId="";
      Admin admin=null;
      if(request.getParameter("adminId")!=null && request.getParameter("adminId").length()>0){
    	  adminId=request.getParameter("adminId");
    	  admin=new AdminDAO().findById(Integer.parseInt(adminId));
      }
      %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加用户</title>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.STYLE1 {font-size: 12px;}
.STYLE4 {
	font-size: 12px;
	color: #1F4A65;
	font-weight: bold;
}

a:link {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;

}
a:visited {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}
a:hover {
	font-size: 12px;
	color: #FF0000;
	text-decoration: underline;
}
a:active {
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.STYLE7 {font-size: 12px;}

</style>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="js/check.js"></script>

<script type="text/javascript">
 function usernamevalidate(){		
    var uname = document.form1.userName.value;
    if(uname==""){
		$("res").innerHTML = "登陆名不能为空";		
	}
	 else{	    
			var url='../admin/login.do';
			var pars='method=nameUniqueValid&userName='+uname+'&adminId=<%=adminId%>';
			var ajax = new Ajax.Updater('res',url,{
			  	parameters : pars
		  	 }
		  	 );
	  	}
}
function check(){
	if(form1.role.value=="0"){
		alert("请选择角色!");
		form1.role.focus();
		return false;
	}
	if(trim(form1.userName.value)==""){
		alert("请填写用户名!");
		form1.userName.focus();
		return false;
	}
	if(form1.userPass.value==""){
		alert("请填写密码!");
		form1.userPass.focus();
		return false;
	}
	if(form1.unit.value==""){
		alert("请填写所属单位!");
		form1.unit.focus();
		return false;
	}
	if(form1.userOrder.value==""){
		alert("请填写序号!");
		form1.userOrder.focus();
		return false;
	}
	if(isNaN(form1.userOrder.value)){
		alert("序号必须是数字");
		form1.userOrder.focus();
		return false;
	}
	form1.submit();
}
</script>
</head>
<%
	RoleDAO dao = new RoleDAO();
	List li = null;
	//得到记录数
	li = null;
	li = dao.findBySql(Role.class,"where id != 3 ");
%>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="30"><img src="images/tab_03.gif" width="15" height="30" /></td>
        <td width="1101" background="images/tab_05.gif"><img src="images/311.gif" width="16" height="16" />
			<span class="STYLE4">用户编辑页面</span></td>
        <td width="281" background="images/tab_05.gif">
        &nbsp;
        </td>
        <td width="14"><img src="images/tab_07.gif" width="14" height="30" /></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="9" background="images/tab_12.gif">&nbsp;</td>
        <td bgcolor="#f3ffe3">
        <form name="form1" id="form1" action="/admin/login.do" method="post"  >
	  <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
        <tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF" class="STYLE1">
          <input type="hidden" name="adminId" value="<%=adminId %>">
          角色：</td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px" class="STYLE1">
		   <select name="role" id="role">
		    <option value="0">请选择
						<% 
							String nowroleid = request.getParameter("roleid");
						if(li!=null){
							Role role;
							for(int i=0;i<li.size();i++)
							{
								role = (Role)li.get(i);
								
								%>
								
<option value="<%=role.getId()%>" <%if(nowroleid!=null&&nowroleid.equals(role.getId()+""))out.print("selected"); %>><%=role.getRoleName() %></option>
								
								<%
							}
						}
						%>
			 </select>
			 <%
			 if(admin!=null){
				 %>
				 <script>
				 $("role").value="<%=admin.getRole().getId()%>";
				 </script>
				 <%
			 }
			 %>
			 <font color="red"><span id="res">*</span></font>
		  </td>
        </tr>
        <tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF" class="STYLE1">用户名：</td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		  <INPUT value="<%=admin==null?"":admin.getAdminName() %>" onMouseOver="" style="BORDER-RIGHT: #f7f7f7 0px solid; BORDER-TOP: #f7f7f7 0px solid; FONT-SIZE: 9pt; BORDER-LEFT: #f7f7f7 0px solid; WIDTH: 100px; BORDER-BOTTOM: #c0c0c0 1px solid; HEIGHT: 16px; BACKGROUND-COLOR: #EEE1ED" onfocus=this.select(); onMouseOut="" maxLength="50" name="userName" id="userName" onblur="usernamevalidate();" this.style.background="#ffffff";>
		  <font color="red"><span id="res">*</span></font>
		  </td>
        </tr>
        <tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF" class="STYLE1">密码：</td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		  <INPUT value="" onMouseOver="" style="BORDER-RIGHT: #f7f7f7 0px solid; BORDER-TOP: #f7f7f7 0px solid; FONT-SIZE: 9pt; BORDER-LEFT: #f7f7f7 0px solid; WIDTH: 100px; BORDER-BOTTOM: #c0c0c0 1px solid; HEIGHT: 16px; BACKGROUND-COLOR: #EEE1ED" onfocus=this.select(); onMouseOut="" maxLength="50" name="userPass" value="" id="userPass" type="password" this.style.background="#ffffff";>
		  <font color="red"><span id="res">*</span></font>
		  </td>
        </tr>
        <tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF" class="STYLE1">审核权限：</td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
          <input type="checkbox" name="isAss" <%=(admin!=null && "on".equals(admin.getIsAss()))? "checked":"" %> />
		  <font color="red"><span id="res">*</span></font>
		  </td>
        </tr>
        <tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF" class="STYLE1">所属单位：</td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
          		<input type="text" name="unit" value="<%=admin==null?"":admin.getUnit()%>"/>
          		<font color="red"><span id="res">*</span></font>
		  </td>
        </tr>
		<tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF" class="STYLE1">序号：</td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
          		<input type="text" name="userOrder" value="<%=admin==null?"":admin.getUserOrder()%>">
          		<font color="red"><span id="res">*</span></font>
		  </td>
        </tr>
       
       
       <tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF" class="STYLE1">真实姓名：</td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		 <input maxLength="50" name="fullName" value="<%=admin==null?"":admin.getFullName() %>" /> 
		  </td>
        </tr>
        
        <tr>
          <td height="30" colspan="2" align="center" valign="middle" bgcolor="#FFFFFF">
		  <input type="hidden" value="<%=adminId.trim().length()>0?"adminUp":"addAdmin" %>" name="method"/>
		  <input type="button" value="提交" onclick="check();"/>
		  </td>
        </tr>
      </table>
	  </form>
        </td>
        <td width="9" background="images/tab_16.gif">&nbsp;</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td height="29">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="29"><img src="images/tab_20.gif" width="15" height="29" /></td>
        <td background="images/tab_21.gif">
        &nbsp;</td>
        <td width="14"><img src="images/tab_22.gif" width="14" height="29" /></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>


</html>
<script type="text/javascript">
var message = "<%=session.getAttribute("message")%>";
if(message!=null && message!="null" && message !=""){
   alert(message);
  }
</script>
<%
	session.removeAttribute("message");
%>